
//懒汉模式

public class SingletonLazy {
    //定义一个全局的变量
    private static SingletonLazy instance = null;

    //构造私有化
    private SingletonLazy(){}
    public static SingletonLazy getInstance(){
        //第一次判断是否需要加锁
        synchronized (SingletonLazy.class){
            //判断对象是否已经创建过
            if (instance == null){
                instance = new SingletonLazy();
            }
        }
        return instance;
    }
}
